<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <div id="app">
        <my-box></my-box>
    </div>




    <template id="box">
        <!-- template 中只能有一个子元素 -->
        <div>
            <h2>
                我是父组件 -- {{ price }}
            </h2>
            <button @click="add">点我</button>
            <my-son></my-son>
        </div>
    </template>

    <template id="son">
        <div>
            <h4>
                我是子组件 ---  {{ price }}
            </h4>
        </div>
    </template>


    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>


        // 子组件
        let Son = {
            template: "#son",
            data() {
                return {
                    price: 200
                }
            },
        }

        // 父组件
        let Box = {
            template: "#box",
            data() {
                return {
                    price: 200
                }
            },
            components: {
                "my-son": Son
            },
            methods: {
                add() {
                    this.price += 1
                }
            }
        }

        new Vue({
            // 元素
            el: "#app",
            components: {
                "my-box": Box
            }
        })
    </script>
</body>

</html>